tests: Add possibility to set invalid UTF-8 and clear clipboard
authorBenjamin Otte <otte@redhat.com>
Sat, 25 Nov 2017 07:37:03 +0000 (08:37 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 3 Dec 2017 04:46:47 +0000 (05:46 +0100)
tests/testclipboard2.c

index c333a0ff3852ff877c413384d519727886f01c43..635e0636825cd586c163d342a91f1d1b23e2c822 100644 (file)
@@ -160,7 +160,8 @@ add_provider_button (GtkWidget          *box,
 
   button = gtk_button_new_with_label (name);
   g_signal_connect (button, "clicked", G_CALLBACK (provider_button_clicked_cb), clipboard);
-  g_object_set_data_full (G_OBJECT (button), "provider", provider, g_object_unref);
+  if (provider)
+    g_object_set_data_full (G_OBJECT (button), "provider", provider, g_object_unref);
 
   gtk_container_add (GTK_CONTAINER (box), button);
 }
@@ -168,6 +169,9 @@ add_provider_button (GtkWidget          *box,
 static GtkWidget *
 get_button_list (GdkClipboard *clipboard)
 {
+  static const guchar invalid_utf8[] = {  'L', 'i', 'b', 'e', 'r', 't', 0xe9, ',', ' ',
+                                         0xc9, 'g', 'a', 'l', 'i', 't', 0xe9, ',', ' ',
+                                          'F', 'r', 'a', 't', 'e', 'r', 'n', 'i', 't', 0xe9, 0 };
   GtkWidget *box;
   GValue value = G_VALUE_INIT;
 
@@ -175,6 +179,11 @@ get_button_list (GdkClipboard *clipboard)
 
   gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("Set Clipboard:"));
 
+  add_provider_button (box,
+                       NULL,
+                       clipboard,
+                       "Empty");
+
   g_value_init (&value, GDK_TYPE_PIXBUF);
   g_value_take_object (&value, gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                                          "utilities-terminal",
@@ -200,6 +209,12 @@ get_button_list (GdkClipboard *clipboard)
                        clipboard,
                        "text/plain");
 
+  add_provider_button (box,
+                       gdk_content_provider_new_for_bytes ("text/plain;charset=utf-8",
+                                                           g_bytes_new_static (invalid_utf8, sizeof(invalid_utf8))),
+                       clipboard,
+                       "Invalid UTF-8");
+
   return box;
 }